package com.nanmeishu.serviceserver.service;

import com.nanmeishu.serviceserver.utils.XmlUtils;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import javax.jws.WebService;
import java.io.ByteArrayInputStream;


@WebService
public class TestService implements ITestService {
    @Override
    public String getWeatherByCityname(String name) {
        System.out.println(name+"测试");
        return name+"测试";
    }

    @Override
    public String byXmlTest(String xml) {
        XmlUtils xmlUtils= null;
        try {
//            Document document = DocumentHelper.parseText(xml);
            xmlUtils = new XmlUtils(new ByteArrayInputStream(xml.getBytes("UTF-8")));
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(xmlUtils.getElementText("driver"));
        return null;
    }

    @Override
    public String OperationA(String xml) {
        System.out.println("--------------------");
        System.out.println(xml);
        System.out.println("-------------------");
        // 1、创建document对象
        Document document = DocumentHelper.createDocument();
        Element response = document.addElement("Response");
        Element msgInfo = response.addElement("MsgInfo");
        Element msg = msgInfo.addElement("Msg");
        Element headInfo = msg.addElement("ExamInfo");
        headInfo.addElement("EXAM_NO").setText("345");
        Element examItemInfo = headInfo.addElement("ExamItemInfo");
        examItemInfo.addElement("EXAM_ITEM_NAME").setText("qweqwe");
        Element reportInfo = msg.addElement("ReportInfo");
        reportInfo.addElement("PDF_URL").setText("http://192.168.1.107:9000/image/systemLogo.png");
        return document.asXML();
    }
}
